package com.amado.course20Tree;


/**
 * Created by Administrator on 2018/6/20.
 */
public class NodeService {
	/**
	 * 一级菜单 
	 */
    private Node[] nodeArray  = new Node[100];
    NodeService(){
    	init();
    }
    void init(){
    	Node node1_1_1 = new Node("node1_1_1","菜单1_1_1");
    	Node node1_1_2 = new Node("node1_1_2","菜单1_1_2");
    	Node node1_1 = new Node("node1_1","菜单1_1",new Node[]{node1_1_1,node1_1_2});
    	Node node1_2 = new Node("node1_2","菜单1_2");
    	Node node1 = new Node("node1","菜单1",new Node[]{node1_1,node1_2});
    	Node node2_1 = new Node("node2_1","菜单2_1");
    	Node node2 = new Node("node2","菜单2",new Node[]{node2_1});
    	Node node3 = new Node("node3","菜单3");
    	
    	nodeArray[0]=node1;
    	nodeArray[1]=node2;
    	nodeArray[2]=node3;
    }
    /**
     * 添加节点
     * @param parentNodeCode 父节点CODE
     * @param nodeName 节点名称
     */
    public void addNode(String parentNodeCode,String nodeName){

    }
    /**
     * 删除节点
     * @param nodeName 节点code
     * @return 成功返回true,否则返回false
     */
    public boolean deleteNode(String nodeName){
        return true;
    }
    /**
     * 修改节点
     * @param nodeCode 节点编号
     * @param nodeName 节点名称
     */
    public void updateNode(String nodeCode,String nodeName){

    }

    /**
     * 打印所有子节点
     */
    public void printNode(){
    	printNode(nodeArray,0);
    }
    /**
     * 打印节点
     * @param nodeArray 菜单数组
     * @param level 菜单级别
     */
    public void printNode(Node[] nodeArray,int level){
    	if(nodeArray==null){
    		return;
    	}
    	for(Node node:nodeArray){
    		if(node!=null){
    			printBlank(level);
    			System.out.println(node.getNodeName());
    			printNode(node.getChildNodes(),level+1);
    		}
    	}
    }
    /**
     * 根据级别打印空格 
     * @param level 菜单级别
     */
	private void printBlank(int level) {
		for(int i=0;i<level;i++){
			System.out.print("    ");
		}
	}
    
    /**
     * 打当nodeCode下的所有子节点
     */
    public void printNode(String nodeCode){

    }

    public static void main(String[] args) {
    	NodeService nodeService = new NodeService();
    	nodeService.printNode();
    }
}
